#lang racket

(define (convert number-list)
  (cond 
    [(check-num-list number-list) (convert-list-number number-list)]
    [else (error 'convert "convert invalid Parameter!")])
  )

(define (check-num n)
  (cond
    [(and (>= n 0) (<= n 9)) true]
    [else false])
  )

(define (check-num-list a-list)
  (cond 
    [(empty? a-list) true]
    [else (and (check-num (first a-list)) 
               (check-num-list (rest a-list)))])
  )

(define (sqrn a n)
  (cond
    [(= n 0) 1]
    [(= n 1) a]
    [else (* a (sqrn a (- n 1)))])
  )

(define (convert-list-number number-list)
  (transform number-list 0)
  )

(define (transform number-list start-exp)
  (cond
    [(empty? (rest number-list)) (* (first number-list)(sqrn 10 start-exp))]
    [else (+ (* (first number-list) (sqrn 10 start-exp))
             (transform (rest number-list) (+ start-exp 1)))]
    )
  )

(define (guess number-list target)
  (define guess-number (convert number-list))
  (cond 
    [(< guess-number target) 'TooSmall]
    [(> guess-number target) 'TooLarger]
    [else 'Perfect])
  )

; Test
(define tbl
  (cons 1
     (cons 2
        (cons 0
           (cons 8    
           (cons 9 empty))))))


(convert tbl)
(guess tbl 346987)